import { ref } from "vue";
import { defineStore } from "pinia";
import { getLogin, getLeftMenu } from "../api/index";
import { getGoList } from "../ulits/getMenuList";
// import type { LoginParams } from '@/types/index.d.ts'
export const useLogin = defineStore("persisted", () => {
  const uid = ref("");
  const LeftList = ref("");
  const Loginn = async (params: any) => {
    const res: any = await getLogin(params);
    if (res.code == 1) {
      uid.value = res.uId;
      localStorage.setItem("img", res.img);

      localStorage.setItem("token", res.token);
      localStorage.setItem("uid", uid.value);
      getLeftList();
      return true;
    } else {
      return false;
    }
  };
  const getLeftList = async () => {
    const uids: any = localStorage.getItem("uid");
    const res: any = await getLeftMenu(uids);
    LeftList.value = getGoList(res.data);
  };

  return { Loginn, uid, getLeftList, LeftList };
});
export const LocalMenuToRoute = () => {
  useLogin().getLeftList();
};
